﻿using System;
using System.Collections;

namespace _08_Console
{
    internal class Program
    {
        static void Main(string[] args)
        {
            #region 动态数组ArrayList

            ///*
            // * 添加操作
            // */
            // ArrayList arr_1 = new ArrayList();
            //arr_1.Add(1);
            //arr_1.Add(1);
            //arr_1.Add(3);
            //arr_1.Add(4);
            //ArrayList arr_2 = new ArrayList();
            //arr_2.AddRange(new int[] {1,2,3,4,5,6,7});

            ///*
            // * 删除操作
            // */

            //arr_1.Remove(1);
            //arr_1.Remove(4);
            //arr_2.RemoveAt(arr_2.Count-1);
            ////arr_2.RemoveRange(2,3);


            //Console.WriteLine("arr_1:");
            //foreach(int i in arr_1)
            //{
            //    Console.WriteLine(i);
            //}
            //Console.WriteLine("arr_2:");
            //for (int i = 0; i < arr_2.Count; i++)
            //{
            //    Console.WriteLine(arr_2[i]);
            //}
            #endregion

            #region 二维数组
            //int[,] arr = new int[2, 3]
            //{
            //    {1,2,3 },
            //    {4,5,6 }
            //};
            //Console.WriteLine($"Length:{arr.Length}");
            //Console.WriteLine($"Rank:{arr.Rank}");
            //Console.WriteLine(arr[1,2]);
            //// 循环遍历
            //foreach(int i in arr) Console.WriteLine(i);
            //求两个二维数组的和
            //int[,] arr1 = new int[,]
            //{
            //    {1,3,5 },
            //    {7,9,2 },
            //    {4,6,8 }
            //};
            //int[,] arr2 = new int[,]
            //{
            //    {2,4,6 },
            //    {8,9,7 },
            //    {3,5,1 }
            //};
            //int[,] sum = new int[3,3];
            //for(int i = 0; i < 3; i++)
            //{
            //    for(int j = 0; j < 3; j++)
            //    {
            //        sum[i,j] = arr1[i, j] + arr2[i,j];
            //        Console.Write($"sum[{i},{j}]:{sum[i,j]}\t");
            //    }
            //    Console.WriteLine();
            //}

            #endregion

            #region 数组参数
            object[] arr = { 12, 12, 45, 78, 2 ,2.2};
            SumArray(arr);
            #endregion
        }

        public static void SumArray(params object[] array)
        {
            double sum = 0;
            foreach (object i in array)
            {
                if(i is int)
                {
                    sum += (int)i;
                }
                else if(i is double)
                {
                    sum += Convert.ToDouble(i);
                }
            }
            Console.WriteLine(sum);
        }
    }
}
